package com.mxx.v3.web.controller;

import com.github.pagehelper.PageInfo;
import com.mxx.v3.utils.PageDto;
import com.mxx.v3.support.RestResponse;
import com.mxx.v3.utils.PageQuery;
import com.mxx.v3.dto.WorkpieceDto;
import com.mxx.v3.service.WorkpieceService;
import com.mxx.v3.web.query.WorkpieceQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/workpiece")
public class WorkpieceController {

    @Autowired
    private WorkpieceService workpieceService;

    @GetMapping("/list")
    public RestResponse list(Integer page, Integer limit, WorkpieceQuery workpieceQuery){

        // TODO 输入校验


        // 封装查询条件
        PageQuery<WorkpieceQuery> workpiecePageQuery = new PageQuery<>();
        workpiecePageQuery.setPage(page);
        workpiecePageQuery.setLimit(limit);
        workpiecePageQuery.setQueryItem(workpieceQuery);

        // 查询
        PageInfo<WorkpieceDto> pageInfo = workpieceService.getWorkpieceList(workpiecePageQuery);



        PageDto<WorkpieceDto> data = new PageDto<>(pageInfo.getTotal(), pageInfo.getList());
        return new RestResponse(data);
    }

    @GetMapping("/test")
    public String test(){
        System.out.println("123---");
        return "123";
    }
}
